#include "http_client.h"

HTTPCliet::HTTPCliet()
{
//   qRegisterMetaType<struct _PlayBack>("PlayBackStruct");//注册PVCI_CAN_OBJ类型
//   qRegisterMetaType<struct _deviceinfo>("struct _deviceinfo");//注册PVCI_CAN_OBJ类型
}

HTTPCliet::~HTTPCliet()
{
    this->deleteLater();
}

void  HTTPCliet::run(){
    httpHandler = new HTTP_Handler();
    this->exec();
}




HTTP_Handler::HTTP_Handler()
{
//    qRegisterMetaType<PlayBackStruct>("PlayBackStruct");//注册PVCI_CAN_OBJ类型
//    qRegisterMetaType<struct _PlayBack>("PlayBackStruct");//注册PVCI_CAN_OBJ类型
}
HTTP_Handler::~HTTP_Handler()
{

}


void HTTP_Handler::http_Post_Sender(bool https,QString ip,QString url,int port,QJsonObject postData){
    QNetworkRequest request;
    QString HTTP_URL;
    if(https){
        HTTP_URL = QString("https://%1:%2%3%4").arg(ip).arg(port).arg(HTTP_URLPREFIX).arg(url);
    }else{
        HTTP_URL = QString("http://%1:%2%3%4").arg(ip).arg(port).arg(HTTP_URLPREFIX).arg(url);
    }
    request.setUrl(QUrl(HTTP_URL));
    request.setRawHeader(QString("Content-Type").toLocal8Bit().data(),QString("application/json;charset=UTF-8").toLocal8Bit().data());
    QJsonDocument httpPack(postData);
    HNetworkReply *reply = new HNetworkReply;
    connect(reply,SIGNAL(reply_rsp(QString,QJsonDocument)),this,SIGNAL(http_replySignal(QString,QJsonDocument)));
    reply->reply_setNetworkReply(httpRecver.post(request,httpPack.toJson(QJsonDocument::Compact).data()));
}


